﻿using System.Collections.Generic;
using System.Threading.Tasks;
using Red.Controls.Diagrams;
using Red.Controls.Diagrams.ViewModels;
using Red.Controls.ViewModels;
using Red.Core.Containers;

namespace Red.Toolkit.NodeDeclaratorEditor
{
    public class DummyOutputConnectorDataItem : DataItem
    {
        #region Data

        private readonly DummyConnectorViewModel _connector;

        #endregion Data

        #region C-tor

        public DummyOutputConnectorDataItem( DataItem parent, DummyConnectorViewModel connector, int id )
            : base( parent )
        {
            _connector = connector;
            IsExpanded = true;
            Title = _connector.IsInherited ? $"[{id}] ( inherited )" : $"[{id}]";
        }

        #endregion C-tor

        #region DataItem implementation

        public override string Type => "Output";

        public override string Value
        {
            get { return ""; }
            set { }
        }

        public override DataItemKind Kind => DataItemKind.Compound;

        protected override Task EnumerateChildrenAsync( IRangedCollection<DataItem> children )
        {
            children.Clear();

            // each output has only two properties: Name and Binding
            children.Add( new DummyOutputConnectorPropertyDataItem( this, _connector, "Name" ) );
            children.Add( new DummyOutputConnectorPropertyDataItem( this, _connector, "Binding" ) );

            if ( !_connector.IsInherited )
            {
                children.Add( new DataButtonItemBase( this, "Remove connector", NodeControlCommands.DeleteDummyConnector, _connector ) );
            }
                

            return Task.CompletedTask;
        }

        #endregion DataItem implementation
    }
}
